package com.qf.leadnewswemedia.web.v1;

import com.qf.leadnewswemedia.service.WmNewsService;
import com.qf.qfleadnewsmodel.commons.dtos.ResponseResult;
import com.qf.qfleadnewsmodel.wemedia.dtos.NewsDto;
import com.qf.qfleadnewsmodel.wemedia.dtos.NewsListDto;
import com.qf.qfleadnewsmodel.wemedia.pojos.WmNews;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class NewsController {

    @Autowired
    private WmNewsService newsService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody NewsListDto newsListDto){
        return newsService.pageQuery(newsListDto);
    }

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody NewsDto newsDto){
        return newsService.submit(newsDto);
    }

    @GetMapping("/one/{newsId}")
    public ResponseResult getOne(@PathVariable("newsId") Integer newsId){
        WmNews wmNews = newsService.getById(newsId);

        return ResponseResult.okResult(wmNews);
    }
}
